package com.alan.camunda.boot.util;

import org.camunda.bpm.engine.impl.el.ExpressionManager;

import java.util.concurrent.atomic.AtomicReference;

/**
 * 使用方式：  Object value = ExpressionManagerHolder.get().getExpression("${_R.data}").getValue(execution);
 */
public class ExpressionManagerHolder {

    private static AtomicReference<CacheableExpressionManager> ref = new AtomicReference<>();

    public static CacheableExpressionManager get() {
        return ref.get();
    }

    public static void set(ExpressionManager expressionManager) {
        if (!ref.compareAndSet(null, new CacheableExpressionManager(expressionManager))) {
            throw new IllegalStateException("ExpressionManager already set");
        }
    }

}
